package org.practice.chart;

import junit.framework.TestCase;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: jack
 * Date: 12-3-30
 * Time: 下午9:22
 * To change this template use File | Settings | File Templates.
 */
public class ChartAction extends TestCase{
    private String chartXML="";

    public void testColumnChart() {
        /*FusionChart columnChart=FusionChartsFactory.createColumnChart("日出缺勤率");
        Map<String,String[]> dataMap=new HashMap<String, String[]>();
        dataMap.put("categories",new String[]{"大班","中班","小班"});//大班，中班，小班(对应categories)
        dataMap.put("出勤率",new String[]{"20","50","30"});//大班出勤率，中班出勤率，小班出勤率(对应Categories)
        dataMap.put("病假率",new String[]{"30","20","50"});//大班病假率，中班病假率，小班病假率
        dataMap.put("事假率",new String[]{"50","20","30"});//大班事假率，中班事假率，小班事假率
        dataMap.put("link",new String[]{"javascript:showPieChart(\""+111+"\")","javascript:showPieChart(\""+222+"\")","javascript:showPieChart(\""+333+"\")"});
        System.out.println("修改前caption===" + columnChart.caption);
        DataTransferUtil.changeChartProp(columnChart, "caption=修改后的标题");
        System.out.println("修改后caption===" + columnChart.caption);
        chartXML=columnChart.generateXML(dataMap);*/

        ChartAttributeVO chartAttributeVO=new ChartAttributeVO("日出缺勤率");
        chartAttributeVO.addCategories(new String[]{"大班","中班","小班"});//大班，中班，小班(对应categories)
        chartAttributeVO.addDatset("出勤率", new String[]{"20", "50", "30"}, "color1");//大班出勤率，中班出勤率，小班出勤率(对应Categories)
        chartAttributeVO.addDatset("病假率",new String[]{"30","20","50"},"color2");//大班病假率，中班病假率，小班病假率
        chartAttributeVO.addDatset("事假率",new String[]{"50","20","30"});//大班事假率，中班事假率，小班事假率
        //大班参数，中班参数，小班参数
        chartAttributeVO.addLink(new String[]{"javascript:showPieChart(\""+111+"\")","javascript:showPieChart(\""+222+"\")","javascript:showPieChart(\""+333+"\")"});
        //设置属性prop="key1=value1,key2=value2....
        chartAttributeVO.setGraphProps("caption=修改后的标题,alternateHGridAlpha=111111");
        chartAttributeVO.setCategoriesProps("font=Arial,fontSize=12,fontColor=000000");

        FusionChart columnChart=FusionChartsFactory.createColumnChart(chartAttributeVO);
        chartXML=columnChart.generateXML();

        //        System.out.println("========="+chartXML);
        DataTransferUtil.printLayoutString(chartXML);

        String expected="true";
        assertEquals("提示信息：返回的结果跟预期不一致",expected,"true");
    }

    public void testPieChart() {
        ChartAttributeVO chartAttributeVO=new ChartAttributeVO("口腔情况");
        chartAttributeVO.addSet("21.3%","21.3%%26lt;br%26gt;（龋齒人数：10人）","color1");
        chartAttributeVO.addSet("78.7%","78.7%%26lt;BR%26gt;（无龋齒人数：35人）","color2");
        chartAttributeVO.addLink(new String[]{"javascript:openUrl(%26apos;基金会普陀幼儿园%26apos;,0);","javascript:openUrl(%26apos;绿洲幼儿园%26apos;,1);)"});
        FusionChart pieChart=FusionChartsFactory.createPieChart(chartAttributeVO);
        chartXML=pieChart.generateXML();
        System.out.println("========="+chartXML);
        DataTransferUtil.printLayoutString(chartXML);
    }


    public void testLineChart() {
        ChartAttributeVO chartAttributeVO=new ChartAttributeVO("第12周出勤率状态图");
        chartAttributeVO.addCategories(new String[]{"04月23日","04月24日","04月25日","04月26日"});//大班，中班，小班(对应categories)
        chartAttributeVO.addDatset("实验幼儿园", new String[]{"87.96","0","24.29","55.55"}, "#4476b6");//大班出勤率，中班出勤率，小班出勤率(对应Categories)
        chartAttributeVO.addDatset("基金会普陀幼儿园",new String[]{"82.76","85.44","84.29","0"},"#b94542");//大班病假率，中班病假率，小班病假率
        chartAttributeVO.setCategoriesProps("font=Arial,fontSize=14,fontColor=abcdef");
        FusionChart lineChart=FusionChartsFactory.createLineChart(chartAttributeVO);
        chartXML=lineChart.generateXML();
        DataTransferUtil.printLayoutString(chartXML);
    }
    public String getChartXML() {
        return chartXML;
    }

    public void setChartXML(String chartXML) {
        this.chartXML = chartXML;
    }
}
